package com.welink.cmp.meatdata.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.welink.cmp.convertor.GenericConvertor;
import com.welink.cmp.dao.metadata.dataobject.VpcDO;
import com.welink.cmp.dto.metadata.MetadataIdListQry;
import com.welink.cmp.dto.metadata.vpc.CreateVpcAddCmd;
import com.welink.cmp.dto.metadata.vpc.VpcCO;
import com.welink.cmp.dto.metadata.vpc.VpcListByPageQry;
import com.welink.cmp.meatdata.command.VpcCmdExe;
import com.welink.common.dto.PageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yanwei li create  2024-05-31 19:12
 */
@Service
public class VpcAppService {

    @Autowired
    private VpcCmdExe vpcCmdExe;

    public Long addVpc(CreateVpcAddCmd addCmd){
        return vpcCmdExe.save(addCmd);
    }

     /* 根据ID获取Switch
     *
     * @param id Switch ID
     * @return Switch业务对象
     */
    public VpcCO getVpcById(Long id) {
        return vpcCmdExe.queryById(id);
    }

    /**
     * 列表查询Switch
     *
     * @param listQry 列表查询条件
     * @return Switch业务对象列表
     */
    public List<VpcCO> vpcListQuery(MetadataIdListQry listQry) {
        return vpcCmdExe.listQuery(listQry);
    }

    /**
     * 分页查询Switch
     *
     * @param pageQry 分页查询条件
     * @return 分页响应，包括Switch列表和分页信息
     */
    public PageResponse<VpcCO> vpcPageQuery(VpcListByPageQry pageQry) {
        final Page<VpcDO> pageR = vpcCmdExe.pageQuery(pageQry);
        final List<VpcDO> records = pageR.getRecords();
        final List<VpcCO> coList = GenericConvertor.toCOList(records,VpcCO.class);
        return PageResponse.of(coList,pageR.getTotal(),pageR.getSize(),pageR.getCurrent());
    }
}
